<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript" src="/js/jquery-3.6.0.min.js"></script>
		<link href="../css/login.css" type="text/css" rel="stylesheet">
    	<link href="../css/tb.css" type="text/css" rel="stylesheet">
	</head>
	<body>

		<div id="main" class="main-warp">
			<div class="main-content">
				<div class="formDiv">

					<h2 class="text-center">登录</h2>

					<form id="loginForm">
						<div class="dataform">
							<div class="input-warp gap">
								<span class="input-icon iconfont icon-yonghu1"></span>
								<input id="userName" name="userName" type="text" class="inputs" placeholder="昵称/手机号/邮箱" maxlength="64">
							</div>
							<div class="error-content">
								<span id="userNameErr" class="errMsg"></span>
							</div>

							<div class="input-warp gap">
								<span class="input-icon iconfont icon-baomi"></span>
								<input class="inputs" type="password" name="userPass" placeholder="密码" id="pwd" maxlength="20">
							</div>
							<div class="error-content">
								<span id="passwordErr" class="errMsg"></span>
							</div>

							<div class="btn-warp gap">
								<div class="text-center">
									<input id="btnLogin" class="btn btn-block lgbtn blue" type="button" value="登录" onclick="login()">
<!--									<button id="btnLogin" class="btn btn-block lgbtn blue" onclick="login()">登录</button>-->
								</div>
							</div>
							<div class="gap">
								<div class="pull-right" style="margin-top: 6px">
									<a href="/login/toRegister?role=0" class="link">用户注册</a><span class="split-space">|</span>
									<a href="/login/toRegister?role=1" class="link">企业注册</a>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		//登录
		function login(){
			if($("#userName").val()!= '' && $("#userName").val()!= null && $("#pwd").val()!= '' && $("#pwd").val()!= null){
				$.ajax({
					url:"/login/login",
					type:"post",
					data:$("form").serialize(),
					dataType:"text",
					success:function(data){
						if(data=="2"){
							alert("账号不存在");
							return;
						}
						if(data=="3"){
							alert("密码错误");
							return;
						}
						if(data=="success"){
							location.href="/login/index";
						}
					},error:function(){
						alert("登录失败");
					}
				})
			}else {
				alert("请填写登录信息");
			}

		}
	</script>
</html>